<template>
  <div>
    <navs>
      <div slot="center">购物街</div>
    </navs>
    <swiper :banner="banner" />
    <recommend :recommends="recommend" />
    <homefitrue></homefitrue>
    <navcontrol :navitem="['流行', '新款', '精选']" @changeType="changeType" />
    <info :showGoods="goods[currentType].list" />
    <ul>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
      <li>你好</li>
    </ul>
  </div>
</template>
<script>
import navs from 'components/common/NavagationBar/nav.vue'
import { getHomeMultidata, getHomeGoods } from 'network/home.js'
import swiper from './HomeChild/homechild'
import recommend from './HomeChild/homerecommend.vue'
import homefitrue from './HomeChild/futrue.vue'
import navcontrol from 'components/content/NavControl/navcontrol.vue'
import info from 'components/content/showInfo/infodata.vue'
export default {
  data() {
    return {
      banner: [],
      recommend: [],
      currentType: 'pop',
      goods: {
        'new': {
          page: 0,
          list: []
        },
        'pop': {
          page: 0,
          list: []
        },
        'sell': {
          page: 0,
          list: []
        }
      }
    }
  },
  components: {
    navs,
    swiper,
    recommend,
    homefitrue,
    navcontrol,
    info
  },
  created() {
    this.getHomeMultidata()
    this.getHomeGoods('new')
    this.getHomeGoods('pop')
    this.getHomeGoods('sell')
  },
  methods: {
    changeType(index) {
      switch (index) {
        case 0:
          this.currentType = 'pop'
          break;
        case 1:
          this.currentType = 'new'
          break;
        case 2:
          this.currentType = 'sell'
          break;
      }
    },
    getHomeMultidata() {
      getHomeMultidata().then(res => {
        this.banner = res.data.banner.list;
        this.recommend = res.data.recommend.list;
      })
    },
    getHomeGoods(type) {
      let page = this.goods[type].page + 1
      getHomeGoods(type, page).then(res => {
        this.goods[type].list.push(...res.data.list)
        this.goods[type].page = page
      })
    }
  }
}
</script>
<style scoped>
</style>